<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>返回上一个 MySQL 操作中的错误信息的数字编码</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.mysql-drop-db.html">mysql_drop_db</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.mysql-error.html">mysql_error</a></div>
 <div class="up"><a href="ref.mysql.html">MySQL 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.mysql-errno" class="refentry">
   <div class="refnamediv">
    <h1 class="refname">mysql_errno</h1>
    <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">mysql_errno</span> &mdash; <span class="dc-title">
     返回上一个 MySQL 操作中的错误信息的数字编码
    </span></p>

   </div>
   <div class="refsect1 unknown-seealsp" id="refsect1-function.mysql-errno-unknown-seealsp">
    <h3 class="title">说明</h3>
     <div class="methodsynopsis dc-description">
      <span class="type">int</span> <span class="methodname"><strong>mysql_errno</strong></span>
       ([ <span class="methodparam"><span class="type">resource</span> <code class="parameter">$link_identifier</code></span>
     ] )</div>

    <p class="para rdfs-comment">
     返回上一个 MySQL 函数的错误号码，如果没有出错则返回
     <em>0</em>（零）。
    </p>
    <p class="para">
     从 MySQL 数据库后端来的错误不再发出警告，要用
     <span class="function"><strong>mysql_errno()</strong></span> 来提取错误代码。注意本函数仅返回最近一次
     MySQL 函数的执行（不包括 <span class="function"><a href="function.mysql-error.html" class="function">mysql_error()</a></span> 和
     <span class="function"><strong>mysql_errno()</strong></span>）的错误代码，因此如果要使用此函数，确保在调用另一个
     MySQL 函数之前检查它的值。
    </p>
    <p class="para">
     <div class="example" id="example-1544">
      <p><strong>Example #1 <span class="function"><strong>mysql_errno()</strong></span> 例子</strong></p>
      <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />&nbsp;&nbsp;&nbsp;&nbsp;mysql_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">"localhost"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"mysql_user"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"mysql_password"</span><span style="color: #007700">);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">mysql_select_db</span><span style="color: #007700">(</span><span style="color: #DD0000">"nonexistentdb"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">mysql_errno</span><span style="color: #007700">()&nbsp;.&nbsp;</span><span style="color: #DD0000">":&nbsp;"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">mysql_error</span><span style="color: #007700">().&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">mysql_select_db</span><span style="color: #007700">(</span><span style="color: #DD0000">"kossu"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">mysql_query</span><span style="color: #007700">(</span><span style="color: #DD0000">"SELECT&nbsp;*&nbsp;FROM&nbsp;nonexistenttable"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">mysql_errno</span><span style="color: #007700">()&nbsp;.&nbsp;</span><span style="color: #DD0000">":&nbsp;"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">mysql_error</span><span style="color: #007700">()&nbsp;.&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
      </div>

      <div class="example-contents"><p>
       以上例子将产生如下输出：
      </p></div>
      <div class="example-contents screen">
<div class="cdata"><pre>
1049: Unknown database &#039;nonexistentdb&#039;
1146: Table &#039;kossu.nonexistenttable&#039; doesn&#039;t exist
</pre></div>
      </div>
     </div>
    </p>
    <blockquote class="note"><p><strong class="note">Note</strong>: 
     <p class="para">
      如果指定了可选参数则用给定的连接提取错误代码。否则使用上一个打开的连接。
     </p>
    </p></blockquote>
    <p class="para">
     参见 <span class="function"><a href="function.mysql-error.html" class="function">mysql_error()</a></span>。
    </p>
   </div>

  </div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.mysql-drop-db.html">mysql_drop_db</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.mysql-error.html">mysql_error</a></div>
 <div class="up"><a href="ref.mysql.html">MySQL 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
